package com.hy.erp.inventory.service;

import java.util.List ;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
*/
import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.CityDao;
import com.hy.erp.inventory.dao.interfaces.ICityDao;
import com.hy.erp.inventory.pojo.City;
import com.hy.erp.inventory.pojo.interfaces.ICity;
import com.hy.erp.inventory.service.interfaces.ICityService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:17:18</li>
 * <li>类型名称：CityService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
/*@ Name ( "cityService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
*/
@Component("cityService")
//public class CityService extends AbstractBusinessService < ICity > implements ICityService{
public class CityService extends AbstractBusinessService < CityDao > implements ICityService{
	
	
	private ICityDao cityDao=null;
	
	

	@Resource(name="cityDao")
	public void setCityDao(CityDao cityDao) {
		this.cityDao = cityDao;
	}
	
	@Override
	public boolean addCity(City city) {




		if (null == city) {
			return true;
		}

		else {
			//System.out
			//		.println("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh");

			//ICityDao cityDao = (ICityDao) this.getDao(ICity.class);

			return cityDao.persist(city);
		}
	
	
	
	
	}


	@Override
	public boolean modifyCity(City city) {



		if ((null == city) || (null == city.getIdentifier())
				|| (city.getIdentifier().trim().length() == 0)) {
			return true;
		} else {

			/*ICityDao cityDao = (ICityDao) this.getDao(ICity.class);

			if (null == city) {
				throw new ArchitectureFoundationException(
						"修改实体数据时发生错误，所需要修改的实体在数据库中并不存在");
			}*/

			return (cityDao.merge(city) != null);
		}
	
	}

	@Override
	public Integer removeCity(String[] cityIds) {



		if ( ( null == cityIds)
			     || ( cityIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{

				//ICityDao cityDao =
                //    ( ICityDao ) this
                //                       .getDao ( ICity.class ) ;
//
				return cityDao
				                .remove ( cityIds ) ;
			}
	
	
	
	}


	@ Override
	public String [ ] addCity (
								Object [ ] city )
	{

		if (null == city) {
			return null;
		}

		else {

			//ICityDao cityDao = (ICityDao) this.getDao(ICity.class);

			City[] citys = new City[city.length];
			for (int i = 0; i < city.length; i++) {
				City city2 = (City) city[i];
				citys[i] = city2;
			}
			return cityDao.persist(citys);

		}
	
	}


	@ Override
	public List < City > getAllCity ( )
	{
		//ICityDao cityDao =
         //   ( ICityDao ) this
         //                      .getDao ( ICity.class ) ;

		return cityDao
		                .find ( ) ;
	}


	@ Override
	public List < City > getCityByQueryName (
												String queryName ,
												Object [ ] args )
	{
		//ICityDao cityDao =
        //    ( ICityDao ) this
         //                      .getDao ( ICity.class ) ;
		return cityDao.findByNamedQuery ( queryName , args ) ;
	}


	@ Override
	public String [ ] modifyCity (
									Object [ ] city )
	{


		if ( null == city)
		{
			return null ;
		}
		
		else
		{
			

			//ICityDao cityDao = (ICityDao) this.getDao(ICity.class);

			City[] citys = new City[city.length];
			for (int i = 0; i < city.length; i++) {
				City city2 = (City) city[i];
				citys[i] = city2;
			}
			return cityDao.merge(citys);
			
			
			
		}
		
	
	
	}

	@Override
	public City findCityById(String id) {
		return cityDao.findByIdentifier(id);
	}
}
